import os
import time

import page
from base.base import Base


class PageOrderAfterSale(Base):
    # 点击申请售后
    def page_click_apply_aftersale(self):
        self.base_click_element(page.get_aftersale_elements()['aftersale'])

    # 选择售后类型
    def page_choose_aftersale_type(self):
        self.base_click_element(page.product_aftersale_type)

    # 选择退款原因
    def page_choose_refund_reason(self):
        self.base_scroll_to_element(page.product_aftersale_foot)
        self.base_click_element(page.product_refund_reason_drop_down)
        self.base_click_element(page.product_aftersale_refund_reason)

    # 填写退款说明
    def page_input_refund_desc(self, comment):
        self.base_in_element_input(page.product_aftersale_refund_desc, comment)

    # 上传凭证
    def page_upload_proof(self, image):
        self.base_click_element(page.product_aftersale_upload_proof)
        self.base_switch_to_iframe(page.product_aftersale_file_iframe)
        image_path = os.path.abspath(image)
        self.base_upload_hidden_file(page.product_aftersale_image_file, image_path)

    # 点击开始上传
    def page_click_start_upload(self):
        self.base_click_element(page.product_aftersale_image_upload)
        time.sleep(1)

    # 点击确认
    def page_click_confirm(self):
        self.base_switch_to_parent_frame()
        self.base_click_element(page.product_aftersale_image_submit)

    # 点击售后提交按钮
    def page_click_submit_aftersale(self):
        self.base_click_element(page.product_aftersale_submit)

    # 点击立即退货
    def page_click_return_goods_now(self):
        self.base_click_element(page.product_aftersale_return_goods)

    # 输入快递名称
    def page_input_express_name(self, express_name):
        self.base_in_element_input(page.product_aftersale_express_name, express_name)

    # 输入快递号
    def page_input_express_number(self, express_number):
        self.base_in_element_input(page.product_aftersale_express_number, express_number)

    # 点击提交按钮
    def page_click_submit_express_info(self):
        self.base_click_element(page.product_express_submit)

    # 获取处理完成后信息
    def page_aftersale_info(self):
        return self.base_get_element_text(page.product_aftersale_info)

    def page_scroll_return_goodes(self):
        self.base_scroll_to_element(page.product_aftersale_return_goods)

    def page_aftersale_return(self):
        self.base_click_element(page.product_return_index)

    def page_aftersale(self, comment, image):
        self.page_choose_aftersale_type()
        time.sleep(3)
        self.page_choose_refund_reason()
        self.page_input_refund_desc(comment)
        self.page_upload_proof(image)
        self.page_click_start_upload()
        self.page_click_confirm()
        self.page_click_submit_aftersale()

    def page_return_process(self, express_name, express_number):
        self.base_refresh()
        self.page_click_return_goods_now()
        self.page_input_express_name(express_name)
        self.page_input_express_number(express_number)
        self.page_click_submit_express_info()
